package com.ptszyxx.popose.module.main.report.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

public class ReportVM extends BaseViewModel<CommonRepository> {
    public String userId;
    public ObservableField<String> input = new ObservableField<>();
    public String feedbackType;

    public ReportVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onSelectAvatarEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onCloseCommand = new BindingCommand(()-> YActivityUtil.getInstance().close(this));
    public BindingCommand onSaveCommand = new BindingCommand(()-> requestUser());

    /**
     * 请求用户信息
     */
    public void requestUser(){
        if(YStringUtil.isEmpty(input.get())){
            YToastUtil.showShort(R.string.hint_input_report);
            return;
        }
        if(YStringUtil.isEmpty(feedbackType)){
            YToastUtil.showShort(R.string.hint_type_report);
            return;
        }

        Map<String, String> params = new HashMap<>();
        params.put("leixing","3");//举报类型 1、动态 2、房间 3用户
        params.put("bjbid",userId);
        params.put("message",input.get());
        params.put("feedbacktype",feedbackType);

        HttpUtils.getInstance()
                .data(model.reportSave(params), this,
                        new OnSuccessResult() {
                            @Override
                            public void onSuccessResult(BaseResponse response) {
                                YToastUtil.showShort(R.string.save_success);
                                YActivityUtil.getInstance().close(ReportVM.this);
                            }
                        });
    }



}
